<?php

namespace SL\BackBundle\Controller;

use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\Security\Core\SecurityContext;

use SL\FrontBundle\Form\PageType;
use SL\FrontBundle\Form\ProjetType;
use SL\FrontBundle\Entity\Projet;
//use SL\FrontBundle\Entity\Page;

class AdminController extends Controller
{
	public function indexAction()
	{
		return ($this->render('SLBackBundle:Admin:index.html.twig'));
	}

	public function loginAction()
	{
		if ($this->get('security.context')->isGranted('IS_AUTHENTICATED_REMEMBERED'))
			return ($this->redirect($this-generateUrl('sl_back_indexprojet')));

		$request = $this->getRequest();
		$session = $request->getSession();
		
		if ($request->attributes->has(SecurityContext::AUTHENTICATION_ERROR))
			$error = $request->attributes->get(SecurityContext::AUTHENTICATION_ERROR);
		else
		{
			$error = $session->get(SecurityContext::AUTHENTICATION_ERROR);
			$session->remove(SecurityContext::AUTHENTICATION_ERROR);
		}
		
		return ($this->render('SLBackBundle:Admin:login.html.twig', array('last_username' => $session->get(SecurityContext::LAST_USERNAME), 'error' => $error)));
	}
	
}
